//
//  CHSViewController.m
//  ZXLoginKit
//
//  Created by 海参 on 10/09/2022.
//  Copyright (c) 2022 海参. All rights reserved.
//

#import "CHSViewController.h"
#import <UMVerify/UMVerify.h>
#import <ZXLoginKit/ZXLoginKit.h>

@interface CHSViewController ()

@end

@implementation CHSViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)oneKeyLoginAction:(id)sender {
    __weak typeof(self) weakSelf =self;
//    [UMCommonHandler checkEnvAvailableWithAuthType:UMPNSAuthTypeLoginToken complete:^(NSDictionary * _Nullable resultDic) {
//        NSString *resultCode = [resultDic objectForKey:@"resultCode"];
//        if ([resultCode isEqualToString:PNSCodeSuccess])  {
//            [weakSelf oneKeyLoginWithComplete:^(NSDictionary * _Nonnull resultDic) {
//
//            }];
//        }
//    }];
    [[ZXLoginAPI sharedInstance]checkOneKeyLoginEnvAvailableWithComplete:^(BOOL enable) {
        if (enable)  {
            [[ZXLoginAPI sharedInstance]chsOneKeyLoginWithController:weakSelf model:nil complete:^(NSDictionary * _Nonnull resultDic) {
                            
            }];
        }
    }];
}

- (void)oneKeyLoginWithComplete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete{
    [UMCommonHandler getLoginTokenWithTimeout:3 controller:self model:nil complete:^(NSDictionary * _Nonnull resultDic) {
        NSString *resultCode = [resultDic objectForKey:@"resultCode"];
        if ([resultCode isEqualToString:PNSCodeSuccess]) {
            NSString *token = [resultDic objectForKey:@"token"];
            NSDictionary *param = @{@"accessToken":token};
        }
        else if ([resultCode isEqualToString:PNSCodeLoginControllerClickCancel]) {
            [UMCommonHandler cancelLoginVCAnimated:YES complete:nil];
            if (complete) {
                complete(resultDic);
            }
        }
        else{
            if (complete) {
                complete(resultDic);
            }
        }
    }];
}
@end
